<template>
  <div v-loading="loading">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="index" width="50"> </el-table-column>
      <el-table-column prop="name" label="科目" width="180"> </el-table-column>
      <el-table-column prop="number" label="题数" width="180">
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small"
            >出题</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import tikuApi from "@/api/tiku/tiku";
export default {
  data() {
    return {
      loading: false,
      tableData: [],
    };
  },
  methods: {
    handleClick: async function (e) {
      this.loading = true;
        let download = await tikuApi.random(e.name);
        if (download=='已下载题目') {
          console.log("开始下载答案")
          //下载答案
          await tikuApi.answer(e.name);
        }
        this.loading = false;
    },
    getTiku: async function () {
      this.loading = true;
      let tiku = await tikuApi.getTiku();
      let data = tiku.data.data;
      for (let i = 2; i < data.length; i++) {
        let element = JSON.parse(data[i]);
        let number = element.title.length;
        let name = element.name;
        this.tableData.push({ name, number });
      }
      this.loading = false;
    },
  },
  created() {
    this.getTiku();
  },
};
</script>

<style>
</style>